package com.ruoyi.project.user.usermapper.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.user.usermapper.domain.UserMapper;
import com.ruoyi.project.user.usermapper.service.IUserMapperService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户映射Controller
 * 
 * @author shixiangwen
 * @date 2022-10-11
 */
@Controller
@RequestMapping("/user/usermapper")
public class UserMapperController extends BaseController
{
    private String prefix = "user/usermapper";

    @Autowired
    private IUserMapperService userMapperService;

    @RequiresPermissions("user:usermapper:view")
    @GetMapping()
    public String usermapper()
    {
        return prefix + "/usermapper";
    }

    /**
     * 查询用户映射列表
     */
    @RequiresPermissions("user:usermapper:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserMapper userMapper)
    {
        startPage();
        List<UserMapper> list = userMapperService.selectUserMapperList(userMapper);
        return getDataTable(list);
    }

    /**
     * 导出用户映射列表
     */
    @RequiresPermissions("user:usermapper:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserMapper userMapper)
    {
        List<UserMapper> list = userMapperService.selectUserMapperList(userMapper);
        ExcelUtil<UserMapper> util = new ExcelUtil<UserMapper>(UserMapper.class);
        return util.exportExcel(list, "usermapper");
    }

    /**
     * 新增用户映射
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户映射
     */
    @RequiresPermissions("user:usermapper:add")
    @Log(title = "用户映射", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserMapper userMapper)
    {
        return toAjax(userMapperService.insertUserMapper(userMapper));
    }

    /**
     * 修改用户映射
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        UserMapper userMapper = userMapperService.selectUserMapperById(id);
        mmap.put("userMapper", userMapper);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户映射
     */
    @RequiresPermissions("user:usermapper:edit")
    @Log(title = "用户映射", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserMapper userMapper)
    {
        return toAjax(userMapperService.updateUserMapper(userMapper));
    }

    /**
     * 删除用户映射
     */
    @RequiresPermissions("user:usermapper:remove")
    @Log(title = "用户映射", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userMapperService.deleteUserMapperByIds(ids));
    }
}
